/**   
 * @Title: ParamDataServiceImpl.java 
 * CopyRight(c)2010-DMX 
 */
package com.dmx.fw.service.impl;

import java.util.List;

import org.apache.log4j.Logger;

import com.dmx.fw.bean.mapping.pojo.ParameterData;
import com.dmx.fw.bean.mapping.pojo.ParameterDescription;
import com.dmx.fw.dao.interfaces.ParamDataDao;
import com.dmx.fw.service.impl.BaseServiceImpl;
import com.dmx.fw.service.interfaces.DictionaryService;
import com.dmx.fw.service.interfaces.ParamDataService;

/** 
 * @Description: ParamData Service Implement
 * @author: system
 * @date: 2006
 * @version V1.0 
 * 
 */
public class ParamDataServiceImpl extends BaseServiceImpl implements ParamDataService{
	private static Logger log = Logger.getLogger(ParamDataServiceImpl.class);

	private ParamDataDao paramDataDao;
	
	private DictionaryService dictionaryService;
	
	/**
	 * <p>Description: 创建ParameterData</p> 
	 * @param paramData
	 * @return Long
	 * @see com.dmx.fw.service.interfaces.ParamDataService#create(com.dmx.fw.bean.mapping.pojo.ParameterData)
	 */
	public Long create(ParameterData paramData ){
		
		Long retId = this.paramDataDao.create(paramData);
		return retId;
	}
	
	/**
	 * 
	 * @Description: 刷新缓存
	 * @param  parmCode  
	 * @return void  
	 * @exception
	 */
	public void flushCache(String typeCode){
		try{
			dictionaryService.flushCacheByCacheCode(typeCode);
		}catch(Exception e){
			e.printStackTrace();
			log.error(e);
		}
	}
	
	/**
	 * <p>Description: 根据ID,删除ParameterData</p> 
	 * @param paramDataId 
	 * @see com.dmx.fw.service.interfaces.ParamDataService#delete(java.lang.String)
	 */
	public void delete(String paramDataId){
		ParameterData paramData=getParamData(paramDataId);
		this.paramDataDao.delete(paramDataId);
	}
	
	/**
	 * <p>Description: 更新ParameterData</p> 
	 * @param paramData 
	 * @see com.dmx.fw.service.interfaces.ParamDataService#update(com.dmx.fw.bean.mapping.pojo.ParameterData)
	 */
	public void update(ParameterData paramData){
		this.paramDataDao.update(paramData);
	}

	/**
	 * <p>Description: 根据ID加载ParameterData</p> 
	 * @param paramDataId
	 * @return 
	 * @see com.dmx.fw.service.interfaces.ParamDataService#getParamData(java.lang.String)
	 */
	public ParameterData getParamData(String paramDataId){
		return this.paramDataDao.getParamData(paramDataId);
	}
	
	/**
	 * <p>Description: 判断某一typeCode下name是否唯一</p> 
	 * @param typeCode
	 * @param name
	 * @param parmDataId
	 * @return 
	 * @see com.dmx.fw.service.interfaces.ParamDataService#nameUniqueCheck(java.lang.String, java.lang.String, long)
	 */
	public boolean nameUniqueCheck(final String typeCode,final String name,final long parmDataId){
		return paramDataDao.nameUniqueCheck(typeCode,name,parmDataId);
	}
	
	/**
	 * <p>Description: 判断某一typeCode下code,name是否唯一</p> 
	 * @param typeCode
	 * @param code
	 * @param name
	 * @return 
	 * @see com.dmx.fw.service.interfaces.ParamDataService#uniqueCheck(java.lang.String, java.lang.String, java.lang.String)
	 */
	public boolean uniqueCheck(final String typeCode,final String code,final String name){
		return paramDataDao.uniqueCheck(typeCode,code,name);
	}

	public ParamDataDao getParamDataDao() {
		return paramDataDao;
	}

	public void setParamDataDao(ParamDataDao paramDataDao) {
		this.paramDataDao = paramDataDao;
	}
	
	/**
	 * <p>Description: 根据typeCode和Code加载ParameterData</p> 
	 * @param code
	 * @param typeCode
	 * @return 
	 * @see com.dmx.fw.service.interfaces.ParamDataService#getParamData(java.lang.String, java.lang.String)
	 */
	public ParameterData getParamData(String code,String typeCode){
		String hql = "select pdata from ParameterData pdata where pdata.code='"
				+ code + "' and pdata.typeCode='"+ typeCode +"' and pdata.status='1'";
		List list = paramDataDao.find(hql);
		if (list!=null && list.size()>0){
			return (ParameterData)list.get(0);
		}
		return null;
		
	}

	public DictionaryService getDictionaryService() {
		return dictionaryService;
	}

	public void setDictionaryService(DictionaryService dictionaryService) {
		this.dictionaryService = dictionaryService;
	}
	
	/**
	 * <p>Description: 根据typeCode获得ParameterDescription</p> 
	 * @param typeCode
	 * @return 
	 * @see @see com.dmx.fw.service.interfaces.ParamDataService#getParmDescByCode(java.lang.String)
	 */
	public ParameterDescription getParmDescByCode(String typeCode){
		String hql = "select parmDesc from ParameterDescription parmDesc where parmDesc.typeCode='" + typeCode + "'";
		List list = paramDataDao.find(hql);
		if (list!=null && list.size()>0){
			return (ParameterDescription)list.get(0);
		}
		return null;
	}

}
